package cn.wolfcode.web.controller;

import cn.wolfcode.domain.JsonResult;
import cn.wolfcode.domain.Permission;
import cn.wolfcode.qo.EmployeeQueryObject;
import cn.wolfcode.service.IPermissionService;
import cn.wolfcode.util.PermissionAnnotation;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/permission")
public class PermissionController {
    private IPermissionService service;

    @Autowired
    public void setService(IPermissionService service) {
        this.service = service;
    }


    @PermissionAnnotation(name = "权限列表",expression = "permission.list")
    @RequestMapping("/list")
    public String list(Model model, EmployeeQueryObject qo){
        PageInfo<Permission> pageInfo = service.getPageInfo(qo);
        model.addAttribute("PageInfo",pageInfo);
        return "permission/list";
    }

    @PermissionAnnotation(name = "重新加载",expression = "permission.reload")
    @RequestMapping("/reload")
    @ResponseBody
    public JsonResult reload(){
        service.reload();
        return new JsonResult();
    }


    @RequestMapping("/noPermission")
    public String noPermission(){
        return "common/nopermission";
    }
}
